package com.dongnaoedu.rpc.redis;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

@Configuration
class AppConfig {
	
	private static final String DEFAULT_HOST = "localhost";
	private static final int DEFAULT_PORT = 6379;

	@Bean
	public JedisConnectionFactory redisConnectionFactory() {
		RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(DEFAULT_HOST, DEFAULT_PORT);
		return new JedisConnectionFactory(config);
	}

	@Bean
	public RedisMessageListenerContainer remoteFreshRedisContainer(RedisConnectionFactory redisConnectionFactory) {
		final RedisMessageListenerContainer container = new RedisMessageListenerContainer();
		container.setConnectionFactory(redisConnectionFactory);
		return container;
	}
}
